package com.baocaiqiche.dev.taoforandroid;

import android.app.Dialog;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.Toast;

import com.squareup.picasso.Picasso;

public class ShowImageActivity extends AppCompatActivity {

    private Dialog dialog ;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_show_image);

        Intent intent = getIntent();
        String url = intent.getStringExtra("url");

        dialog = new Dialog(this, R.style.edit_AlertDialog_style);
        dialog.setContentView(R.layout.show_image);
        ImageView imageView = (ImageView) dialog.findViewById(R.id.showImage);

        Picasso.with(this).load(url).into(imageView);

        dialog.setCanceledOnTouchOutside(true);

        Window w = dialog.getWindow();
        WindowManager.LayoutParams lp = w.getAttributes();
        lp.x = 0;
        lp.y = 40;
        dialog.onWindowAttributesChanged(lp);

        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(ShowImageActivity.this,ImagesActivity.class);
                startActivity(intent);
            }
        });

        dialog.show();

        //Toast.makeText(this,url,Toast.LENGTH_SHORT).show();
    }
}
